package com.benyanyi.viewbind.init;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;

import androidx.annotation.IdRes;
import androidx.annotation.StringRes;

/**
 * @author BenYanYi
 * @date 2018/12/26 09:28
 * @email ben@yanyi.red
 * @overview
 */
public class ViewInit {
    private Activity mActivity;
    private View mView;
    private Dialog mDialog;

    public ViewInit(Activity mActivity) {
        this.mActivity = mActivity;
    }

    public ViewInit(View mView) {
        this.mView = mView;
    }

    public ViewInit(Dialog mDialog) {
        this.mDialog = mDialog;
    }

    public View find(@IdRes int value) {
        if (mActivity != null) {
            return mActivity.findViewById(value);
        } else if (mDialog != null) {
            return mDialog.findViewById(value);
        } else {
            return mView.findViewById(value);
        }
    }

    public String string(@StringRes int value) {
        if (mActivity != null) {
            return mActivity.getString(value);
        } else if (mDialog != null) {
            return mDialog.getContext().getString(value);
        } else {
            return mView.getContext().getString(value);
        }
    }

}
